package com.my.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.RoomService;
import com.my.service.UmbilicalService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * <p>
 * 消毒时间表 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2018-10-12
 */
@Controller
@RequestMapping("/umbilical")
public class UmbilicalController {

    @Autowired
    UmbilicalService umbilicalService;
    //创建日志Logger的对象
    Logger logger = Logger.getLogger(DayController.class);
    @Autowired
    RoomService roomService;





    /**
     * 查询
     */
    @RequestMapping("/selectUmbilical")
    @ResponseBody
    public ResultPage<Umbilical> selectUmbilical(String lin, String data, VoPage voPage,Long id){
        Map map = new HashMap();
        map.put("lin",lin);
        map.put("data",data);
        ResultPage<Umbilical> list = umbilicalService.selectMyPage(map,voPage,id);
        return list;
    }


  /*  *//**
     * 页面添加
     *//*
    @RequestMapping("/insertInput")
    @ResponseBody
    public String  insertInput(String param,Long id){
        System.out.println(param);
        Map<String,Object> map = JSON.parseObject(param,Map.class);
        //1 获得房间号
        Object roomId = map.get("roomId");
        //2  根据房间号查出 房间id
                Map<String,Object> map1 = new HashMap<>();
                map1.put("room_name",roomId);
                List<Room> rooms = roomService.selectByMap(map1);
        String newRoomId = String.valueOf(rooms.get(0).getId());
        //3 重新赋值
        map.put("roomId", newRoomId);
        System.out.println("rooms:"+rooms);



        Object um1 = map.get("um1");
        Object um2 = map.get("um2");
        Object um3 = map.get("um3");


        System.out.println("value:"+um1);
        map.put("umbilicalTime",um1.toString().replace("-",""));
        System.out.println("value:"+um2);
        map.put("umbilicalTime",um2.toString().replace("-",""));
        System.out.println("value:"+um3);
        map.put("umbilicalTime",um3.toString().replace("-",""));






        param = JSON.toJSONString(map);
       System.out.println(param);

        Umbilical umbilical1= JSON.parseObject(um1.toString(),Umbilical.class);
        umbilical1.setMid(Long.valueOf(newRoomId));
        Umbilical umbilical2= JSON.parseObject(um2.toString(),Umbilical.class);
        umbilical2.setMid(Long.valueOf(newRoomId));
        Umbilical umbilical3= JSON.parseObject(um3.toString(),Umbilical.class);
        umbilical3.setMid(Long.valueOf(newRoomId));




        List<Umbilical> list  = new ArrayList<>();
        list.add(umbilical1);
        list.add(umbilical2);
        list.add(umbilical3);



        System.out.println("111111"+umbilical1);
        if (umbilicalService.insertBatch(list)) {
            logger.info("{addmother|保存成功}");
            return "保存成功";
        } else {
            logger.info("{addmother|保存失败}");
            return "保存失败";
        }
    }*/




}
